package com.inspire.myapp;

import java.io.IOException;
import java.util.Enumeration;

import com.codename1.io.Preferences;
import com.codename1.io.Storage;
import com.codename1.io.services.ImageDownloadService;
import com.codename1.ui.Button;
import com.codename1.ui.Container;
import com.codename1.ui.Display;
import com.codename1.ui.Form;
import com.codename1.ui.Image;
import com.codename1.ui.Label;
import com.codename1.ui.animations.CommonTransitions;
import com.codename1.ui.layouts.BorderLayout;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.layouts.LayeredLayout;
import com.codename1.ui.plaf.UIManager;
import com.codename1.ui.util.UITimer;

public class splashscreen {

	public splashscreen() {
		// TODO Auto-generated constructor stub
	}
	static void showSplashScreen() throws IOException{

		final Form splash = new Form();
		BorderLayout border = new BorderLayout();
		border.setCenterBehavior(BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE);
		splash.setLayout(border);
		splash.setScrollable(false);
		Label title = new Label("Inspirat'home");
		title.setUIID("Title");
		final Label subtitle = new Label("By Inspirelec");
		subtitle.setUIID("SplashSubTitle");
		splash.addComponent(BorderLayout.NORTH, title);
		splash.addComponent(BorderLayout.SOUTH, subtitle);

		
		Label as = new Label("Maison");
		Label ah = new Label("Commandes");
		Label ac = new Label("Mobile");
		Label ad = new Label("Gestion");
		final Container back=new Container(new LayeredLayout());
		final Container center = new Container(new LayeredLayout());
		center.addComponent(as);
		center.addComponent(ah);
		center.addComponent(ac);
		center.addComponent(ad);
        
        /*for (String filename : stor.listEntries()) {
        	if (filename.endsWith(".jpg")){
        		Label l=new Label();
        		Object oo=stor.readObject(filename);
				Image im= (Image) oo;
				im=im.scaledHeight(30);
        		l.setIcon(im);
        		center.addComponent(l);	
        	} else {
        		//hi.addComponent(new Label(filename));
        	}
		}*/
		Storage stor=new Storage();
		Image imgtitle=(Image) stor.readObject("/images/inspirathome.gif");
		if (imgtitle!=null) {
			imgtitle=utils.reformeImage(imgtitle, 1, 1, 1, 1, 300, 300);
			final Label icon=new Label(imgtitle);
			back.addComponent(icon);			
		}
		back.addComponent(center);
		splash.addComponent(BorderLayout.CENTER, back);
		splash.show();
		splash.setTransitionOutAnimator(CommonTransitions.createFade(500));//(CommonTransitions.SLIDE_HORIZONTAL, true, 2000));
		

		/*Display.getInstance().callSerially(new Runnable() {
			public void run() {*/
				
				new UITimer(new Runnable() {
					public void run() {
						objets.checkmd5Config(subtitle);
						
						objets.charge=true;
					}
				}).schedule(1, false, splash);
				
				new UITimer(new Runnable() {
					public void run() {
						if (!objets.charge) {
							//System.out.println(objets.charge);
						} else {
							try {
								menuscreen.showMenuScreen();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
						}

					}
				}).schedule(1000, true, splash);
								
								
				center.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
				center.setShouldCalcPreferredSize(true);
				splash.getContentPane().animateHierarchy(1500);
			
				
				new UITimer(new Runnable() {
					public void run() {
						center.setLayout(new BoxLayout(BoxLayout.X_AXIS));
						center.setShouldCalcPreferredSize(true);
						splash.getContentPane().animateHierarchy(1500);
					}
				}).schedule(1500, false, splash);



				
			/*}
		});*/
		
		
	}

}
